<?php
/*
*角色模块
*/
class Role_model extends CI_Model{
	public function __construct(){
		$this->load->database();
	}

	//新建角色
	public function addRole($data){
		return $this->db->insert('admin_role',$data);
	}

	//获取角色
	public function getRole($id){
			$this->db->where('id',$id);
			$query = $this->db->get('admin_role');
			return $query->row_array();
	}
	
	//列出
	public function listRole($s=0,$l=0){
		$this->db->limit($s,$l);
		$rel = $this->db->get('admin_role');
		return $result = $rel->result_array();
	}

	//更新角色
	public function editRole($id,$data){
		$this->db->where('id',$id);
		$this->db->update('admin_role',$data);
		return ($this->db->affected_rows() == 1) ? true : false;
	}

	//更新状态
	public function up_status($id,$status){
		
		$ids = explode(',',$id);
		$this->db->where_in('id',$ids);
		$this->db->update('admin_role',$status);

		if($this->db->affected_rows() > 0){
			return true;
		}else{
			return false;
		}
	}
	//删除角色
	public function deleteRole($id){
		$ids = explode(',',$id);
		$this->db->where_in('id',$ids);
		$this->db->delete('admin_role');
		return ($this->db->affected_rows() >= 1) ? true : false;
	}


}